package com.example.spring.config;

import com.example.spring.service.impl.IndexDao2Impl;
import com.example.spring.service.impl.IndexDaoImpl;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @Author: zhangrongqing
 * @Date: 2020/7/30 21:34
 */
@Component
public class MyBeanPostProccessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("indexDao")){
            System.out.println("我接管了");
            return new IndexDao2Impl();
        }

        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return null;
    }
}
